﻿
import java.util.Arrays;
import java.util.Scanner;

public class Homework4 {
    // 以int类型数组为例
    public static void main(String[] args) {
        int[] arr = new int[10];
        Scanner sc = new Scanner(System.in);
        int index = 0;
        while(true){
            System.out.println("1输入元素，0退出：");
            int type = sc.nextInt();
            if(type == 1){
                System.out.println("请输入元素：");
            }else if(0 == type){
                break;
            }else{
                System.out.println("输入错误");
                continue;
            }
            int number = sc.nextInt();
            arr[index] = number;
            index += 1;
            if(index >= arr.length * 0.8){
                int[] newArr = new int[(int)(arr.length * 1.5)];
                System.arraycopy(arr, 0, newArr,0, index);
                arr = newArr;
                System.out.println("数组已扩容至:" + arr.length);
            }
        }
        int[] print = new int[index];
        System.arraycopy(arr, 0, print, 0, index);
        System.out.println("输入元素：" + Arrays.toString(print));
    }
}
